import axios from '@/request/index'

// 登录
export const loginApi = (username, password) => {
  return axios.post('/admin/login', {
    username,
    password,
  })
}

// 获取登录用户信息
export const getInfoApi = () => {
  return axios.post('/admin/getinfo')
}

// 退出登录
export const logoutApi = () => {
  return axios.post('/admin/logout')
}

// 密码重置
export const resetPasswordApi = (data) => {
  return axios.post('/admin/updatepassword', data)
}

export const getManagerListApi = (page, query = {}) => {
  let q = []
  for (const key in query) {
    if (query[key]) {
      q.push(`${key}=${encodeURIComponent(query[key])}`)
    }
  }
  let r = q.join('&') ? '?' + q.join('&') : ''
  return axios.get(`/admin/manager/${page}?${r}`)
}

export const updateManagerStatusApi = (id, status) => {
  return axios.post(`/admin/manager/${id}/update_status`, {
    status,
  })
}

export const createManagerApi = (data) => {
  return axios.post('/admin/manager', data)
}

export const updateManagerApi = (id, data) => {
  return axios.post(`/admin/manager/${id}`, data)
}

export const deleteManagerApi = (id) => {
  return axios.post(`/admin/manager/${id}/delete`)
}
